package com.chixing.ih.module.programmer.mapper.provider;

import com.chixing.ih.module.programmer.pojo.WorkExper;
import com.chixing.ih.util.EmptyUtil;
import org.apache.ibatis.jdbc.SQL;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 刘岩
 * Date: 2020-09-29
 * Time: 16:56
 *
 * @version 1.0
 */
public class WorkExperMapperProvider {

    public String insertOne() {
        return new SQL() {{
            INSERT_INTO("tbl_work_experience");
            VALUES("user_id", "#{userId}");
            VALUES("begin_time", "#{beginTime}");
            VALUES("end_time", "#{endTime}");
            VALUES("company", "#{company}");
            VALUES("position", "#{position}");
            VALUES("work_experience_description", "#{workExperDesc}");
            VALUES("prove_image_url", "#{proveImageUrl}");
            VALUES("create_time", "#{createTime}");
        }}.toString();
    }



    public String deleteOneById() {
        return new SQL() {{
            UPDATE("tbl_work_experience");
            SET("is_deleted=1");
            WHERE("id=#{id}");
        }}.toString();
    }


    public String updateOne(WorkExper workExper) {
        return new SQL() {{
            UPDATE("tbl_work_experience");
            if (!EmptyUtil.isEmpty(workExper.getBeginTime())) {
                SET("begin_time=#{beginTime}");
            }
            if (!EmptyUtil.isEmpty(workExper.getEndTime())) {
                SET("end_time=#{endTime}");
            }
            if (!EmptyUtil.isEmpty(workExper.getCompany())) {
                SET("company=#{company}");
            }
            if (!EmptyUtil.isEmpty(workExper.getPosition())) {
                SET("position=#{position}");
            }
            if (!EmptyUtil.isEmpty(workExper.getWorkExperDesc())) {
                SET("work_experience_description=#{workExperDesc}");
            }
            if (!EmptyUtil.isEmpty(workExper.getProveImageUrl())) {
                SET("prove_image_url=#{proveImageUrl}");
            }
            WHERE("id=#{id}");

        }}.toString();

    }

    public String listAll() {
        return new SQL() {{
            SELECT("*");
            FROM("tbl_work_experience");
            WHERE("is_deleted=0 AND user_id=#{userId}");
        }}.toString();
    }




}
